<div id="content" class="container_12">
    <div class="grid_12 header-border">
        <input type="button" name="addnewuser" value="Add New User" onClick="anchor('<?php echo base_url(); ?>admin/um?action=add');" id="add-user-button" class="silver-button float-right" />
        <h2>User Management</h2>
    </div>
    <div class="clear"></div>
    <div class="grid_12">
        <fieldset>
            <legend>Search for Users</legend>
            <form action="<?php echo base_url(); ?>admin/um" method="GET">
                <input type="hidden" name="page" value="1" />
                <table class="margin-center">
                    <tr>
                        <td>Keywords:</td>
                        <td>Search By:</td>
                        <td>Sort By:</td>
                        <td>Sort Type:</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="keywords" class="form-input"<?php if(isset($_GET['keywords'])){echo ' value="'.$_GET['keywords'].'"';} ?> />
                        </td>
                        <td>
                            <select name="searchby" class="form-select">
                                <option value="account_id"<?php if(isset($_GET['searchby']) AND $_GET['searchby'] == 'account_id'){echo ' selected';} ?>>Account ID</option>
                                <option value="username"<?php if(isset($_GET['searchby']) AND $_GET['searchby'] == 'username'){echo ' selected';} ?>>Username</option>
                                <option value="fullname"<?php if(isset($_GET['searchby']) AND $_GET['searchby'] == 'fullname'){echo ' selected';} ?>>Full Name</option>
                                <option value="lastlogin"<?php if(isset($_GET['searchby']) AND $_GET['searchby'] == 'lastlogin'){echo ' selected';} ?>>Last Login</option>
                            </select>
                        </td>
                        <td>
                            <select name="sortby" class="form-select">
                                <option value="account_id"<?php if(isset($_GET['sortby']) AND $_GET['sortby'] == 'account_id'){echo ' selected';} ?>>Account ID</option>
                                <option value="username"<?php if(isset($_GET['sortby']) AND $_GET['sortby'] == 'username'){echo ' selected';} ?>>Username</option>
                                <option value="fullname"<?php if(isset($_GET['sortby']) AND $_GET['sortby'] == 'fullname'){echo ' selected';} ?>>Full Name</option>
                                <option value="lastlogin"<?php if(isset($_GET['sortby']) AND $_GET['sortby'] == 'lastlogin'){echo ' selected';} ?>>Last Login</option>
                            </select>
                        </td>
                        <td>
                            <select name="sorttype" class="form-select">
                                <option value="asc"<?php if(isset($_GET['sorttype']) AND $_GET['sorttype'] == 'asc'){echo ' selected';} ?>>Ascending</option>
                                <option value="desc"<?php if(isset($_GET['sorttype']) AND $_GET['sorttype'] == 'desc'){echo ' selected';} ?>>Descending</option>
                            </select>
                        </td>
                        <td>
                            <input type="submit" name="submit" value="Search" class="form-button" />
                        </td>
                    </tr>
                </table>
            </form>
        </fieldset><br />
            <?php
            
            if(count($userlist) > 0) {
                foreach($userlist as $user) {
                    echo '<div class="search-result">';
                        if($user->avatar != null) {
                            echo '<img src="'.base_url().'account/getavatar/'.$user->account_id.'" alt="avatar" class="thumbnail float-left" />';
                        } else {
                            echo '<img src="'.base_url().'images/unknown_user.jpg" alt="avatar" class="thumbnail float-left" />';
                        }
                        echo '<div class="grid_10">';
                        if($this->session->userdata('level') > $user->level OR $this->session->userdata('account_id') == $user->account_id) {
                            echo '<input type="button" value="Update Account" onClick="anchor(\''.base_url().'account/profile?id='.$user->account_id.'&amp;action=update\');" class="silver-button float-right" />';
                        }
                        echo '<h3><a class="search-link" href="'.base_url().'account/profile?id='.$user->account_id.'">'.$user->f_name.' '.$user->l_name.'</a></h3>';
                        echo 'Account ID: '.$user->account_id.'<br />';
                        echo 'Username: '.$user->username.'<br />';
                        echo 'Gender: '.$user->gender.'<br />';
                        echo 'Birthday: '.$user->birthday.'<br />';
                        echo 'Last Login: '.$user->last_login;
                        echo '</div>';
                        echo '<div class="clear"></div>';
                    echo '</div>';
                }
                echo '<div class="pagination">Pages:&nbsp;';
                echo displayPages($totalpage,10);
                echo '</div>';
            }
            
            ?>
    </div>
</div>